var fs = require('fs');
var path = require('path');

var stdin = process.stdin;

var nowPath = __dirname;
console.log("请输入:");
stdin.on('data',(chunk)=>{
    var arr = chunk.toString().split(" ")
    var mode = arr[0];
    
    var name = arr[1].slice(0,-2);
    
    if (mode == "mkdir") {
        fs.mkdir(name,0777,(err)=>{
            if (err) {
                console.log(err)
            } else {
                console.log("文件目录创建成功！！")
            }
        })
    }
    else if (mode == "touch") {
        var myPath = nowPath+"/filedir/"+name;
        fs.mkdir("filedir",0777,(err)=>{
            if (err) {
                console.log(err)
            }
        })
        fs.writeFile(myPath,"hello node",function (e) {
            if (e) {
                console.log("文件创建失败");
            } else {
                console.log("文件创建成功！！");
            }
        })
    }
    else if (mode == "delete") {
        var myPath = nowPath+"/filedir/"+name;
        fs.unlink(myPath,function (e) {
            if (e) {
                console.log(e)
            } else {
                console.log("文件删除成功！！")
                process.exit();
            }
        })
    }
})